package com.xiashitech.agent.instrumentation.db.statement.sanitizer;

import com.xiashitech.agent.config.StartConfig;
import com.xiashitech.agent.constants.XSConstants;
import com.xiashitech.agent.proxy.hutool.MapUtil;
import com.xiashitech.agent.instrumentation.db.statement.sanitizer.impl.XSSqlLocalSanitizer;
import com.xiashitech.agent.instrumentation.db.statement.sanitizer.impl.XSSqlSanitizer;
import com.xiashitech.interfaces.agent.dto.AgentConfigDTO;
import com.xiashitech.interfaces.apiservice.UserTracingMsg;

public class SanitizerFactory {

    private static final XSSqlSanitizer sanitizer = new XSSqlSanitizer();

    public static UserTracingMsg create() {
        UserTracingMsg sqlSanitizer = null;
        String sanitizerMode = null;
        if (AgentConfigDTO.getConfig() == null){
            sanitizerMode = XSConstants.SANITIZER_MODE_LOCAL; // 兼容单元测试
        }else {
            sanitizerMode = MapUtil.getStr(AgentConfigDTO.getConfig().getSqlSanitizer(), StartConfig.getParamValueFromKey(StartConfig.systemId));
        }
        if (XSConstants.SANITIZER_MODE_SERVER.equalsIgnoreCase(sanitizerMode)) {
            // supplement UserTracing by remote AgentServer
            sqlSanitizer = sanitizer;
        } else {
            // supplement UserTracing by Agent LocalService
            sqlSanitizer = XSSqlLocalSanitizer.getInstance();
        }
        return sqlSanitizer;
    }
}
